package com.bym.mall.controller;

import com.bym.mall.form.OrderCreateForm;
import com.bym.mall.service.IOrderService;
import com.bym.mall.vo.ResponseVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;

/**
 * <p>
 * 前端控制器
 * </p>
 *
 * @author bym
 * @since 2022-06-22
 */
@Api(value = "订单模块")
@Controller
@RequestMapping("/mall/order")
public class OrderController {

    @Autowired
    private IOrderService orderService;

    @ApiOperation(value = "创建订单")
    @PostMapping("/")
    public ResponseVo create(@RequestBody @Valid OrderCreateForm orderCreateForm) {
        return orderService.create(orderCreateForm.getShippingId());
    }

    @ApiOperation(value = "订单列表")
    @GetMapping("/")
    public ResponseVo list(@RequestParam(value = "pageNum", required = false, defaultValue = "1") Integer pageNum,
                           @RequestParam(value = "pageSize", required = false, defaultValue = "1") Integer pageSize) {
        return orderService.list(pageNum, pageSize);
    }

    @ApiOperation(value = "订单详情")
    @GetMapping("/{orderNo}")
    public ResponseVo detail(@PathVariable Long orderNo) {
        return orderService.detail(orderNo);
    }

    @ApiOperation(value = "取消订单")
    @PutMapping("/{orderNo}")
    public ResponseVo cancel(@PathVariable Long orderNo) {
        return orderService.cancel(orderNo);
    }
}
